package com.yoomiito.app.adapter.shopcar;

import androidx.annotation.Nullable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yoomiito.app.R;
import com.yoomiito.app.model.order.ShopCarGoods;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.utils.SpannableUtils;
import com.yoomiito.app.utils.inputfilter.TextInputFilter;
import com.yoomiito.app.widget.RoundImageView;

import java.util.List;

public class ShopCarBuyAdapter extends BaseQuickAdapter<ShopCarGoods, BaseViewHolder> {

    public ShopCarBuyAdapter(@Nullable List<ShopCarGoods> data) {
        super(R.layout.item_goods_6, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShopCarGoods item) {
        EditText notesEt = helper.getView(R.id.notes);
        notesEt.setFilters(new InputFilter[]{new TextInputFilter(true).setLength(20)});
        notesEt.setText(TextUtils.isEmpty(item.getNotes()) ? "" : item.getNotes());
        notesEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setNotes(s.toString());
            }
        });
        RoundImageView goodsIv = helper.getView(R.id.item_order_goods_iv);
        ImageLoader.getInstance().into(goodsIv.getContext(), item.getProduct_img(), goodsIv);
        helper.setText(R.id.item_order_goods_title,item.getProduct_name());
        helper.setText(R.id.item_order_goods_price,"¥" + item.getSale_price());
        helper.setText(R.id.goods_size, SpannableUtils.getSmallMoneyFlag("X"+item.getNum(),0.8f));
    }
}
